package com.cq.xjms.web.actions.interceptor;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;

import com.cq.xjms.model.User;
import com.cq.xjms.service.SysManager;
import com.cq.xjms.util.Constants;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 * 后台管理员权限拦截器基类
 * @author caiqiang
 * @version 1
 */
public class LoginAuthInterceptor implements Interceptor {

	private static final long serialVersionUID = 4172679552892871788L;

	private SysManager sysManager;

	public void setSysManager(SysManager sysManager) {
		this.sysManager = sysManager;
	}

	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext invocationContext = invocation.getInvocationContext();
		Object user = invocationContext.getSession().get(Constants.LOGIN_USER);
		if(invocationContext.getActionInvocation().getProxy().getMethod().equals("login")||invocationContext.getActionInvocation().getProxy().getMethod().equals("logout")){
			return invocation.invoke();
		}
		if(user==null){
		  return "login";
		}
		return invocation.invoke();
	}
	@Override
	public void destroy() {
		
	}

	@Override
	public void init() {
		
	}
	

}
